Skip to content

GH-1502: [JDBC] Close the server session on Connection#close without a catalog - #1504

Open
AbhishekPathania wants to merge 3 commits into
apache:mainfrom
AbhishekPathania:jdbc-close-session-without-catalog
Open

AbhishekPathania wants to merge 3 commits into
apache:mainfrom
AbhishekPathania:jdbc-close-session-without-catalog

Conversation

@AbhishekPathania

@AbhishekPathania AbhishekPathania commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What's Changed

Connection#close now sends CloseSession even when no catalog was set, so servers that create a session per connection can free it right away.

  • Without a catalog, statuses that mean there is no session to close (UNIMPLEMENTED, INVALID_ARGUMENT, NOT_FOUND, UNAUTHENTICATED) are logged at debug and ignored. Other errors are handled as with a catalog.
  • The call has a 5 second deadline, so close cannot hang on an unresponsive server. FlightClient#close already waits up to 5 seconds for the channel to shut down.
  • The gRPC channel is now closed even when CloseSession throws.
  • Handlers that getStreams builds for other endpoint locations never send CloseSession. They authenticate with the connection's credentials, so on a server that keys sessions by bearer token, closing one after a failed fetch would end the connection's own session. ADBC's driver also closes only the main client's session.

This matches ADBC's Flight SQL driver, which always sends CloseSession on close.

The code and tests were drafted with an AI assistant (Claude). I reviewed every change and also ran it against our own Flight SQL server, where 25 reconnects left 25 sessions open before this change and none after.

Closes #1502.

@github-actions

This comment has been minimized.

@AbhishekPathania
AbhishekPathania marked this pull request as draft November 18, 2026 14:15
@AbhishekPathania
AbhishekPathania marked this pull request as ready for review November 18, 2026 15:28
@lidavidm lidavidm added the enhancement PRs that add or improve features. label Nov 18, 2026
@github-actions github-actions Bot added this to the 20.0.0 milestone Nov 18, 2026
@AbhishekPathania
AbhishekPathania force-pushed the jdbc-close-session-without-catalog branch 2 times, most recently from 384b190 to 84c8253 Compare November 19, 2026 11:11
fre, "Failed to close Flight SQL session.", "closing Flight SQL session");
} else {
// Without a catalog the driver never asked for a session; the server may not support them.
logSuppressedCloseException(fre, "closing Flight SQL session");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suppresses every FlightRuntimeException when no catalog is configured, including failures such as UNAVAILABLE or UNAUTHENTICATED. In those cases Connection.close() succeeds even though the server session may remain open.

Could we suppress only statuses indicating that the server does not support session catalog, and propagate other failures as we do when a catalog is configured?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fair point. I narrowed it. Without a catalog, close now only ignores statuses that mean there's no session to close:

  • UNIMPLEMENTED: servers without CloseSession (the Java, Go and C++ defaults)
  • INVALID_ARGUMENT: servers that don't know the action, like all Rust servers today (https://github.com/apache/arrow-rs/blob/9951b625879a19844ecd0b2dd352347a87ea26dd/arrow-flight/src/sql/server.rs#L451) and older Java/Go ones
  • NOT_FOUND: ServerSessionMiddleware when no session was created
  • UNAUTHENTICATED: the client isn't (or is no longer) authenticated, so there's no session. Without it, existing tests that connect without credentials (e.g. ConnectionTest#testGetBasicClientNoAuthShouldOpenConnection) fail on close.

Everything else goes through the catalog path.

…nt handlers

Endpoint handlers are built from a copy of the connection's Builder and authenticate with the connection's credentials. On a server that keys sessions by bearer token, a CloseSession from a failed endpoint fetch would end the connection's own session. ADBC's Flight SQL driver likewise never closes sessions from its endpoint clients.
@AbhishekPathania
AbhishekPathania force-pushed the jdbc-close-session-without-catalog branch from 84c8253 to bc7f091 Compare November 19, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement PRs that add or improve features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JDBC] Connection#close does not close the server session unless a catalog is set

3 participants